using Cfg.Exceptions;
using Cfg.Helpers;

namespace Cfg.ValidationAttributes
{
    public class MaxAttribute : CfgValueValidatorBaseAttribute
    {
        public object Max { get; private set; }
        public MaxAttribute(object max, params string[] contexts)
        {
            Contexts = contexts;
            Max = max;
        }

        protected override void Validate(object value)
        {
            if (value.IsGreaterThan(Max))
                throw new OutOfBoundsException(string.Format("{0} exceeds max value {1}", value, Max));
        }
    }
}